package gptma.bo.model.request;

import gptma.bo.model.BaseEntity;
import gptma.bo.model.employee.Employee;

import java.util.Date;
import java.util.List;

import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "estimationDemande")
@AttributeOverride(name = "id", column = @Column(name = "estimationDemandeId"))
public class RequestEvaluation extends BaseEntity {

	private static final long serialVersionUID = 461193078144128261L;

	@Temporal(value = TemporalType.TIMESTAMP)
	@Column(name = "date")
	private Date date;

	@Column(name = "chargeEstimation")
	private Float charge;

	@Column(name = "commentaire")
	private String comment;

	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "auteurId")
	private Employee author;

	@BatchSize(size = 30)
	@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "requestEvaluation", orphanRemoval = true)
	private List<RequestEvaluationElement> elements;

	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "demandeClientId")
	private ClientRequest clientRequest;

	/**
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * @param date
	 *            the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}

	/**
	 * @return the charge
	 */
	public Float getCharge() {
		return charge;
	}

	/**
	 * @param charge
	 *            the charge to set
	 */
	public void setCharge(Float charge) {
		this.charge = charge;
	}

	/**
	 * @return the comment
	 */
	public String getComment() {
		return comment;
	}

	/**
	 * @param comment
	 *            the comment to set
	 */
	public void setComment(String comment) {
		this.comment = comment;
	}

	/**
	 * @return the author
	 */
	public Employee getAuthor() {
		return author;
	}

	/**
	 * @param author
	 *            the author to set
	 */
	public void setAuthor(Employee author) {
		this.author = author;
	}

	/**
	 * @return the elements
	 */
	public List<RequestEvaluationElement> getElements() {
		return elements;
	}

	/**
	 * @param elements
	 *            the elements to set
	 */
	public void setElements(List<RequestEvaluationElement> elements) {
		this.elements = elements;
	}

	/**
	 * @return the clientRequest
	 */
	public ClientRequest getClientRequest() {
		return clientRequest;
	}

	/**
	 * @param clientRequest
	 *            the clientRequest to set
	 */
	public void setClientRequest(ClientRequest clientRequest) {
		this.clientRequest = clientRequest;
	}

}
